package com.tre.jdevtemplateboot.common.authority;

import com.tre.jdevtemplateboot.common.dto.PropertiesConfig;
import com.tre.jdevtemplateboot.common.util.BasedDesUtils;
import com.tre.jdevtemplateboot.common.util.HttpUtils;
import com.tre.jdevtemplateboot.common.util.JwtUtils;
import com.tre.jdevtemplateboot.web.interceptor.HeadToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author JDev
 */
@Component
public class TokenTakeApart {
    @Autowired
    PropertiesConfig propertiesVO;
    public String takeEncryptedUserId() {
        return JwtUtils
                .getClaimsByToken(HeadToken.getHeadToken(HttpUtils.getHttpServletRequest()
                        , propertiesVO.getAuthHeaderKey(), propertiesVO.getAuthTypePrefix()))
                .getId();

    }

    public String takeDecryptedUserId() {
        String ecrypteUserId = JwtUtils
                .getClaimsByToken(HeadToken.getHeadToken(HttpUtils.getHttpServletRequest()
                        , propertiesVO.getAuthHeaderKey(), propertiesVO.getAuthTypePrefix()))
                .getId();
        return BasedDesUtils.decryptBasedDes(ecrypteUserId);
    }
}
